package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-07-12
 * Time: 14:31
 */
public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书...");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想借阅的图书：");
        String name = sc.nextLine();

        int currentSize = bookList.getUsedSized();
        for (int i = 0; i < currentSize; i++) {
            Book book =bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed()){
                    System.out.println("这本书已经被借出去");
                }
                book.setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有你要借阅的书");
    }
}
